package lumis.portal.user;

import lumis.portal.cache.ICloneableCacheEntry;
import lumis.portal.stability.StableMinor;

/**
 * Represents a portal user
 *
 * @version $Revision: 13082 $ $Date: 2011-05-27 16:03:12 -0300 (Fri, 27 May 2011) $
 * @since 4.0.6
 */
@StableMinor(version = "6.0", sinceVersion = "4.0")
public class UserConfig implements ICloneableCacheEntry
{
	public static final String USER_ADMINISTRATOR_ID = "00000000D00000000000000000000001";
    public static final String USER_GUEST_ID = "00000000D00000000000000000000002";
    public static final String USER_FRAMEWORKCLOCK_ID = "00000000D00000000000000000000003";
    public static final String USER_PAGECACHE_ID = "00000000D00000000000000000000004";
    public static final String USER_SYSTEM_ID = "00000000D00000000000000000000005";
    
    public static final int USER_TYPE_COMMON = 0;
    public static final int USER_TYPE_FRAMEWORK = 1;
    
	private String id = null;
    private String login = null;
    private String password = null;
    private String firstName = null;
    private String middleName = null;
    private String lastName = null;
    private String email = null;
    private boolean disabled = false;
    private int type = 0;
    private boolean multiSession = false; 
    private String channelId = null;
    private String origin = null;
    private boolean portalLogin = true;
    
	@Override
	public UserConfig clone()
	{
		try
		{
			return (UserConfig)super.clone();
		}
		catch (CloneNotSupportedException e)
		{
			throw new RuntimeException(e);
		}
	}
	
    /**
     * Indicates if this user may be logged in normally by the portal's
     * default authenticator.
     * <p>
     * Users whose passwords are authenticated externally and should not
     * use the password in the portal database must have this attribute set
     * to false to prevent from being authenticated against the password
     * stored in the portal database. 
     * @return if this user may be logged in normally by the portal's
     * default authenticator.
     * @since 4.0.8
     */
    public boolean isPortalLogin()
	{
		return portalLogin;
	}
    
    /**
     * Sets if this user may be logged in normally by the portal's
     * default authenticator.
     * @param portalLogin the value to set.
     * @see #isPortalLogin()
     * @since 4.0.8
     */
	public void setPortalLogin(boolean portalLogin)
	{
		this.portalLogin = portalLogin;
	}
	
	/**
	 * Returns the origin of this user. The origin is used to identify from 
	 * where the user was added, for example, was imported from an external 
	 * repository.
	 * @return the origin of this user. <code>null</code> indicates the user
	 * was added normally.
	 * @since 4.0.8
	 */
	public String getOrigin()
	{
		return origin;
	}
	
	/**
	 * Sets the origin for this user.
	 * @param origin the origin to set.
	 * @see #getOrigin()
	 * @since 4.0.8
	 */
	public void setOrigin(String origin)
	{
		this.origin = origin;
	}
	
	public boolean isDisabled()
    {
        return disabled;
    }
    public void setDisabled(boolean disabled)
    {
        this.disabled = disabled;
    }
    public String getEmail()
    {
        return email;
    }
    public void setEmail(String email)
    {
        this.email = email;
    }
    public String getFirstName()
    {
        return firstName;
    }
    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }
    public String getId()
    {
        return id;
    }
    public void setId(String id)
    {
        this.id = id;
    }
    public String getLastName()
    {
        return lastName;
    }
    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }
    public String getLogin()
    {
        return login;
    }
    public void setLogin(String login)
    {
        this.login = login;
    }
    public String getMiddleName()
    {
        return middleName;
    }
    public void setMiddleName(String middleName)
    {
        this.middleName = middleName;
    }
    public boolean isMultiSession()
    {
        return multiSession;
    }
    public void setMultiSession(boolean multiSession)
    {
        this.multiSession = multiSession;
    }
    public String getPassword()
    {
        // deve retornar senha encryptografado
        return password;
    }
    public void setPassword(String password)
    {
        // deve receber senha sem ser encryptografado
        //TODO: Encrypt password
        this.password = password;
    }
    public int getType()
    {
       return type;
    }
    public void setType(int type)
    {
        this.type = type;
    }

    public String getChannelId()
	{
		return channelId;
	}

	public void setChannelId(String channelId)
	{
		this.channelId = channelId;
	}

	public String getFullName()
	{
		String fullName = getFirstName();
		if(middleName != null && middleName.length() > 0)
			fullName += " "+middleName;
		if(lastName != null && lastName.length() > 0)
			fullName += " "+lastName;
		
		return fullName;
	}
}
